<template>
    <div>
        <!--卡片-->
        <el-card class="box-card">
            <!--定义面包屑-->
            <el-breadcrumb separator=">">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>系统管理</el-breadcrumb-item>
                <el-breadcrumb-item>用户管理</el-breadcrumb-item>
            </el-breadcrumb>
            <el-divider></el-divider>
            <!--表单的搜索框杀杀杀
                 :model="双向绑定表单的数据"
            -->
            <el-form :inline="true" :model="carTypeFormData"  class="demo-form-inline">
                <el-form-item >
                    <el-input v-model="carTypeFormData.shopname" placeholder="请输入商店名称"></el-input>
                </el-form-item>
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.loginName" placeholder="请输入昵称"></el-input>-->
                <!--                </el-form-item>-->
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.email" placeholder="请输入邮箱"></el-input>-->
                <!--                </el-form-item>-->
                <!--                <el-form-item >-->
                <!--                    <el-input v-model="userFormData.phone" placeholder="请输入电话"></el-input>-->
                <!--                </el-form-item>-->
                <el-form-item>
                    <el-button type="primary" @click="chaxun">查询</el-button>
                    <el-button type="primary" @click="insert">添加</el-button>
                </el-form-item>
            </el-form>

            <!--数据表格-->
            <template>
                <el-table
                        :data="tableData"
                        :border="true"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="编号"
                            width="180">
                    </el-table-column>
<!--                    <el-table-column-->
<!--                            prop="provinceId"-->
<!--                            label="门店名称"-->
<!--                            width="180">-->
<!--                    </el-table-column>-->

<!--                    <el-table-column-->
<!--                            prop="cityId"-->
<!--                            label="门店地址"-->
<!--                            width="180">-->
<!--                    </el-table-column>-->
                    <el-table-column
                            prop="ishot"
                            :formatter="zhuangtaima"

                            label="是否常用"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="shopname"
                            label="门店名称"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="address"
                            label="门店地址"
                            width="180">
                    </el-table-column>
<!--                    <el-table-column-->
<!--                            prop="longitude"-->
<!--                            label="是否常用"-->
<!--                            width="180">-->
<!--                    </el-table-column>-->
<!--                    <el-table-column-->
<!--                            prop="dimensionality"-->
<!--                            label="是否常用"-->
<!--                            width="180">-->
<!--                    </el-table-column>-->
                    <el-table-column
                            prop="addtime"
                            label="时间"
                            width="180">
                    </el-table-column>

                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="primary" icon="el-icon-edit" circle @click="selectById(scope.row.id)"></el-button>
                                                        <el-button type="danger" icon="el-icon-delete" circle @click="deleteById(scope.row.id)"></el-button>
                            <!--                            <el-button type="warning" icon="el-icon-star-off" circle @click="showUserRole(scope.row.userId)"></el-button>-->
                        </template>
                    </el-table-column>
                </el-table>

                <!--                分页-->
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="currentPage"
                        :page-sizes="[5, 10, 15, 20]"
                        :page-size="pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </template>
        </el-card>

        <el-dialog
                title="提示"
                :visible.sync="editDialogVisible"
                width="30%"
        >
            <!--            model:表单数据-->
            <el-form  label-width="100px" :model="carTypeForm" >
                <el-form-item label="id" style="display: none">
                    <el-input v-model="carTypeForm.id" ></el-input>
                </el-form-item>
<!--                <el-form-item label="类型" >-->
<!--                    <el-input v-model="carTypeForm.provinceId"></el-input>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="价钱" >-->
<!--                    <el-input v-model="carTypeForm.cityId"></el-input>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="路径" >-->
<!--                    <el-input v-model="carTypeForm.areaId"></el-input>-->
<!--                </el-form-item>-->
                <el-form-item label="是否常用门店" >
                    <el-radio v-model="carTypeForm.ishot" :label="0">No</el-radio>
                    <el-radio v-model="carTypeForm.ishot" :label="1">Yes</el-radio>
                </el-form-item>
                <el-form-item label="门店名称" >
                    <el-input v-model="carTypeForm.shopname"></el-input>
                </el-form-item>
                <el-form-item label="门店地址" >
                    <el-input v-model="carTypeForm.address"></el-input>
                </el-form-item>
<!--                <el-form-item label="路径" >-->
<!--                    <el-input v-model="carTypeForm.longitude"></el-input>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="路径" >-->
<!--                    <el-input v-model="carTypeForm.dimensionality"></el-input>-->
<!--                </el-form-item>-->

                <el-form-item label="时间" >
                    <el-form-item >
                        <el-date-picker
                                v-model="carTypeForm.addtime"
                                type="date"
                                placeholder="日期">
                        </el-date-picker>
                    </el-form-item>
                </el-form-item>

<!--                <el-form-item label="省市县">-->
<!--                    <div id="app">-->
<!--                        <el-cascader-->
<!--                                size="large"-->
<!--                                :options="options"-->
<!--                                v-model="selectedOptions"-->
<!--                                @change="handleChange">-->
<!--                        </el-cascader>-->
<!--                    </div>-->
<!--                </el-form-item>-->

                <el-form-item label="省">
                    <el-select v-model="carTypeForm.provinceId" placeholder="请选择"  @change="changdeSheng($event)">
                        <el-option

                                v-for="(itemes,index) in sheng"
                                :key="itemes.baseAreaid"
                                :label="itemes.name"
                                :value="itemes.baseAreaid"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="市">
                    <el-select v-model="carTypeForm.cityId" placeholder="请选择" @change="changdeShi($event)">
                        <el-option

                                v-for="(itemes,index) in shi"
                                :key="itemes.baseAreaid"
                                :label="itemes.name"
                                :value="itemes.baseAreaid"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="县">
                    <el-select v-model="carTypeForm.areaId" placeholder="请选择" >
                        <el-option

                                v-for="(itemes,index) in xian"
                                :key="itemes.baseAreaid"
                                :label="itemes.name"
                                :value="itemes.baseAreaid"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="formSubmit">确 定</el-button>
              </span>
        </el-dialog>

    </div>
</template>

<script>
    import { regionDataPlus } from 'element-china-area-data'
    export default {
        name: "Carshop",
        data(){
            return {
                editDialogVisible:false,
                //条件搜索对象
                carTypeFormData:{},
                //表格数据
                tableData:[],
                //每页显示的条数
                pageSize: 5,
                //当前的显示的页码
                currentPage:1,
                //总条数
                total:0,
                carTypeForm:{},
                sheng:[],
                shi:[],
                xian:[],
                options: regionDataPlus,
                selectedOptions: []


            }
        },
        created() {
            this.selectall();
            this.shengShiXian();
        },

        methods:{
            changdeShi(id){
                for (let item of this.shi) {
                    if (item.baseAreaid == id) {
                        this.xian = item.children
                    }
                }
            },
            changdeSheng(id){

                    for (let item of this.sheng) {
                        if (item.baseAreaid == id) {
                            this.shi = item.children
                        }
                    }
            },

            handleChange (value) {
                this.carTypeForm.provinceId = value[0];
                this.carTypeForm.cityId = value[1];
                this.carTypeForm.areaId = value[2];
            },
            shengShiXian(){
                var that=this;
              this.$http.get("rents/shop/shengShiXian").then(function (returnResult) {
                          that.sheng=returnResult.data.result.sheng;
                          console.log(that.sheng)

              })

            },
            formSubmit(){
                var that=this;
                if(this.carTypeForm.id!=null){
                    this.$http.put("rents/shop/update",this.carTypeForm).then(function (returnResult) {
                        that.editDialogVisible=false;
                        that.carTypeForm={};
                        that.selectall();
                    })
                }else {
                    this.$http.post("rents/shop/insert", this.carTypeForm).then(function (returnResult) {
                        that.editDialogVisible = false;
                        that.selectall();
                    })
                }

            },
            selectall(){
                var that=this;
                this.$http.post(`rents/shop/pageSelect/${this.currentPage}/${this.pageSize}`,this.carTypeFormData).then(function (returnResult) {
                    that.total=returnResult.data.result.total;
                    that.tableData=returnResult.data.result.records;


                })
            },
            chaxun(){
                this.selectall();
            },
            insert(){
                this.carTypeForm={};
                this.editDialogVisible=true;

            },
            deleteById(id){
                var that=this;
                this.$http.delete("rents/shop?id="+id).then(function (returnResult) {
                     that.selectall();
                })
            },
            selectById(id){
                var that=this;
                this.$http.get(`rents/shop/selectById/${id}`).then(function (returnResult) {
                    that.editDialogVisible=true;
                    that.carTypeForm=returnResult.data.result.huixian;
                     console.log(that.carTypeForm.provinceId)
                    that.changdeSheng(that.carTypeForm.provinceId)
                     console.log(returnResult);
                    that.changdeShi(that.carTypeForm.cityId);
                })
            },
            handleSizeChange(v){
                this.pageSize=v;
                this.selectall();
            },
            handleCurrentChange(v){
                this.currentPage=v;
                this.selectall();
            },
            zhuangtaima(row,column){
                var status=row.ishot;
                if(status==1){
                    return '是'
                }
                if(status==0){
                    return '不是'
                }

            }

        }
    }
</script>

<style scoped>

</style>